package com.gz.WeChatSys.config;


import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class WxConfig {

    @Value("${wx.appId}")
    private String appId;

    @Value("${wx.secret}")
    private String secret;

    @Value("${wx.aesKey}")
    private String aesKey;

    @Value("${wx.token}")
    private String token;

//    @Resource
//    private Jedis jedis;


    private WxMpConfigStorage wxMpConfigStorage() {
        WxMpInMemoryConfigStorage wxMpInMemoryConfigStorage = new WxMpInMemoryConfigStorage();
        wxMpInMemoryConfigStorage.setAppId(appId);
        wxMpInMemoryConfigStorage.setSecret(secret);
        wxMpInMemoryConfigStorage.setToken(token);
        wxMpInMemoryConfigStorage.setAesKey(aesKey);
        return wxMpInMemoryConfigStorage;
    }

//    @Bean
//    public WxMpConfigStorage wxMpConfigStorage() {
//        WxMpInRedisConfigStorage wxMpInRedisConfigStorage = new WxMpInRedisConfigStorage();
//        wxMpInRedisConfigStorage.setAppId(appId);
//        wxMpInRedisConfigStorage.setSecret(secret);
//        wxMpInRedisConfigStorage.setToken(token);
//        wxMpInRedisConfigStorage.setAesKey(aesKey);
//        wxMpInRedisConfigStorage.setJedis(jedis);
//        return wxMpInRedisConfigStorage;
//    }

    @Bean
    public WxMpService wxMpService() {
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
        /*try {
            wxMpService.getAccessToken(true);
        } catch (Exception e) {
            e.printStackTrace();
        }*/
        return wxMpService;
    }


}
